
import { _decorator, Component, Node } from 'cc';
import { ITEM_TYPE } from '../../../core/common/GameConst';
import BasePanel from '../../../core/component/BasePanel';
import Data from '../../../core/manager/Data';
import GameConst from '../../../core/common/GameConst';
import MsgHints from '../../../core/utils/MsgHints';
import WindowManager from '../../../core/manager/WindowManager';
import { Main } from '../Main';
import WXTTUtils from '../../../core/manager/WXTTUtils';
import AudioMgr from '../../../core/utils/AudioMgr';
const { ccclass, property } = _decorator;

@ccclass('BuyItemLayer')
export class BuyItemLayer extends BasePanel {

    private type: ITEM_TYPE;
    setItemType(type: ITEM_TYPE) {
        this.type = type;
        this.GetGameObject("Magnet").active = type == ITEM_TYPE.Magnet;
        this.GetGameObject("Hint").active = type == ITEM_TYPE.Hint;
        this.GetGameObject("Frozen").active = type == ITEM_TYPE.Frozen;
        this.GetGameObject("Time").active = type == ITEM_TYPE.Time;
        this.SetText("lbl_name", GameConst.getItemName(type))

        Main.Instance()._GameUI.pasue = true;

    }


    onDestroy() {
        super.onDestroy();
        Main.Instance()._GameUI.pasue = false;
    }

    onBtnClicked(event: any, customEventData: any) {
        AudioMgr.Instance().playSFX('btnclick')
        var btnName = event.target.name;
        switch (btnName) {
            case "btn_close":
                this.close();
                break;
            case "btn_buy":
                if (Data.user.coin < 90) {
                    WindowManager.ins.open("BuyCoinLayer");
                }
                else {
                    MsgHints.show("购买成功！");
                    Data.user.coin -= 90;
                    Data.user.addItem(this.type, 3);
                    Data.save();

                    this.close();
                }
                break;
        }
    }
}

